#!/usr/bin/env python
# encoding: utf-8
"""
graphs.py

Created by Grégoire Détrez on 2009-02-20.
Copyright (c) 2009 Grégoire Détrez. All rights reserved.
"""

import sys
import os
import unittest
import yapgvb

NODE_COLORS = {
    "SENT": 'red',
    "Srel": 'red',
    "Sint":  'red',
    "Ssub":  'red',
    "PP": 'green',
    "NP": 'green',
    "AP": 'green',
    "VN": 'orange',
    "VPpart":  'orange',
    "VPinf": 'orange',
    "COORD":  'violet',
    "w": 'yellow',
}

class TreeNode2Digraph(yapgvb.Digraph):
    def __init__(self, tree_node):
        yapgvb.Digraph.__init__(self, "TreeNode2Digraph_tree")
        self.rec_add_tree(tree_node)
    
    def rec_add_tree(self, tn):
        label = unicode(tn)
        if label == "w":
            if tn.getattr("cat"):
                label = tn.getattr("cat")
        label = label.encode("utf-8")
        node = self.add_node(None,
            label = label,
            style = "filled",
            color = NODE_COLORS.get(tn.nodeName, 'gray'))
        for a_child in tn.children():
            child_node = self.rec_add_tree(a_child)
            e = node >> child_node
            if a_child.function:
                e.label = a_child.function
        return node
    

class GraphsFactoryTests(unittest.TestCase):
    def setUp(self):
        pass


if __name__ == '__main__':
    unittest.main()